package ink.lovejinhu.leetcode;

/**
 * @Author: jin
 * @Date: 2021/9/7 20:39
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0209 {
    /**
     * 长度最小的子数组
     *
     * @param target
     * @param nums
     * @return nums[i]+nums[i+1]+.....num[j]>=target
     * 暴力
     */
    public int minSubArrayLen(int target, int[] nums) {
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i; j < nums.length; j++) {
                int sum = getSum(nums, i, j);
                if (sum >= target) {
                    if (j - i + 1 < min) {
                        min = j - i + 1;
                    }
                    break;
                }
            }
        }
        return min == Integer.MAX_VALUE ? 0 : min;
    }

    public int getSum(int[] nums, int left, int right) {
        int sum = 0;
        for (int i = left; i <= right; i++) {
            sum += nums[i];
        }
        return sum;

    }
}
